package a66weding.com.jiehuntong.activity.toolstask;

import android.app.Dialog;
import android.content.Intent;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import java.util.HashMap;
import java.util.Map;

import a66weding.com.jiehuntong.R;
import a66weding.com.jiehuntong.application.GlobalApplication;
import a66weding.com.jiehuntong.common.utils.CUtils;
import a66weding.com.jiehuntong.pager.BasePager;
import a66weding.com.jiehuntong.pager.ToolsPager_Task_Addtask;
import a66weding.com.jiehuntong.pager.Tools_DeletetaskPager;
import a66weding.com.jiehuntong.pager.Tools_UpdatewedPager;

public class ToolsWedTaskActivity extends BaseWedTaskActivity implements View.OnClickListener {
    private Button btnCancle;
    private Dialog setDialog;
    private RelativeLayout rlTimesort;

    private ImageView ivRsort, ivHsort, addtask_iv;
    private TextView mBackTv, mTitleTv, mAddTv, tvDeltask, tvTimesort, tvUpdatewed;
    private LinearLayout mHeadBackLay;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tools_wed_task);

        initview();
    }

    private void initview() {
        ((GlobalApplication) getApplication()).getActivityManager().addActivity("Tools_MaramissActivity", this);
        addtask_iv = (ImageView) findViewById(R.id.bianjiStory_addtask_iv);
        mHeadBackLay = (LinearLayout) findViewById(R.id.lay_head_backlay);

        mBackTv = (TextView) findViewById(R.id.headleft_title_tv);
        mTitleTv = (TextView) findViewById(R.id.headcenter_title_tv);
        mAddTv = (TextView) findViewById(R.id.headright_title_tv);

        mTitleTv.setText("结婚任务");
        mAddTv.setText("设置");
        mBackTv.setText("工具");

        addtask_iv.setOnClickListener(this);
        mHeadBackLay.setOnClickListener(this);
        mAddTv.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.bianjiStory_addtask_iv://添加任务
                CUtils.showToast("添加任务");

                Intent intent = new Intent(this, ToolsWedTaskAddtaskActivity.class);
                startActivity(intent);

                break;
            case R.id.lay_head_backlay://返回
                finish();
                break;
            case R.id.headright_title_tv://我的设置
                //我的设置
                CUtils.showToast("我的设置");
                showMyPop();
                break;
            case R.id.setting_cancel_btn: //取消

                setDialog.dismiss();
                break;
            case R.id.setting_deltask_tv: //删除任务


                setDialog.dismiss();
                break;
            case R.id.setting_updatewed_tv:  //修改婚期


                setDialog.dismiss();
                break;
            case R.id.setting_timesort_rl:
                //时间排序
                break;
        }
    }

    /**
     * 弹出popupwindow修改婚期、删除任务、时间排序
     */
    private void showMyPop() {
        setDialog = new Dialog(this, R.style.dialog);
        setDialog.setContentView(R.layout.tools_setting_dialog);
        btnCancle = (Button) setDialog.findViewById(R.id.setting_cancel_btn);
        rlTimesort = (RelativeLayout) setDialog.findViewById(R.id.setting_timesort_rl);
        tvDeltask = (TextView) setDialog.findViewById(R.id.setting_deltask_tv);
        tvUpdatewed = (TextView) setDialog.findViewById(R.id.setting_updatewed_tv);
        ivRsort = (ImageView) setDialog.findViewById(R.id.setting_rsort_iv);


        tvDeltask.setOnClickListener(this);
        tvUpdatewed.setOnClickListener(this);
        btnCancle.setOnClickListener(this);
        rlTimesort.setOnClickListener(this);

        Window window = setDialog.getWindow();
        // 可以在此设置显示动画
        WindowManager.LayoutParams wl = window.getAttributes();
        wl.x = 0;
        wl.y = getWindowManager().getDefaultDisplay().getHeight();
        // 以下这两句是为了保证按钮可以水平满屏
        wl.width = ViewGroup.LayoutParams.MATCH_PARENT;
        wl.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        // 设置显示位置
        setDialog.onWindowAttributesChanged(wl);
        setDialog.show();
    }










}
